package rlyy.framework.core.common.request;

import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;

/**
 * 以线程绑定的形式公开请求内容
 * @author yuanqinglong
 * @since 2020/11/27 13:46
 */
public abstract class GrpcRequestContextHolder {


    private static final ThreadLocal<FullRequest> REQUEST_ATTRIBUTES_HOLDER =
            new NamedThreadLocal<>("gRPC Request Parameters");

    public static void setRequestAttributes(@Nullable FullRequest fullRequest) {
                REQUEST_ATTRIBUTES_HOLDER.set(fullRequest);
    }

    public static FullRequest getRequestAttributes() {
       return REQUEST_ATTRIBUTES_HOLDER.get();
    }

    public static void resetRequestAttributes() {
        REQUEST_ATTRIBUTES_HOLDER.remove();
    }
}
